<?php

class EmployeeController{
    
    public function queryEmployee(){
        $pageNo = $_POST["pageNo"];
        $pageSize = $_POST["pageSize"];
        $dbutil = new DBUtil();
        $sql = "select e.empid,e.empName,e.age,e.gender,e.phone,e.email,d.deptName,e.entryDate from tb_employee e,tb_dept d where e.deptid=d.deptid";
        $searchEmpName = isset($_POST["searchEmpName"])?$_POST["searchEmpName"]:"";
        $searchGender = isset($_POST["searchGender"])?$_POST["searchGender"]:0;
        $searchDeptid = isset($_POST["searchDeptid"])?$_POST["searchDeptid"]:0;
        
        if($searchEmpName != ""){
            $sql .= " and e.empName like '%$searchEmpName%'";
        }
        if($searchGender > 0){
            $sql .= " and e.gender=$searchGender";
        }
        if($searchDeptid > 0){
            $sql .= " and e.deptid=$searchDeptid";
        }
        
        
        
        $sql .= " order by e.empid desc";
        $page = $dbutil->queryByPage($sql, $pageNo, $pageSize);
        echo json_encode($page);
    }
    
    public function loadAllDept(){
        $dbutil = new DBUtil();
        $sql = "select * from tb_dept";
        echo json_encode($dbutil->query($sql));
    }
    
    
}

?>